package com.zut.controller;


import com.zut.mapper.BookorderMapper;
import com.zut.pojo.Bookorder;
import com.zut.pojo.Parents;
import com.zut.service.BookorderService;
import com.zut.service.ParentsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bookorder
 * @since 2021-06-06
 */
@Controller
@RequestMapping("/bookorder")
public class BookorderController {
    @Resource
    private BookorderService bookorderService;

    @Resource
    private ParentsService parentsService;

    @Resource
    private BookorderMapper bookorderMapper;

    //预约课程
    @RequestMapping("/bookClass")
    private String bookClass(Integer parid, Integer teaid, Integer week, Integer day, Date ordertime,Model model){
        int i = bookorderService.bookClass(parid, teaid, week, day,ordertime);
        if(i==1){
            model.addAttribute("msg","预约成功");
            return "single-course";
        }else{
            model.addAttribute("msg","预约失败");
            return "single-course";
        }
    }

    //查看已预约课程
    @RequestMapping("/selectAllBookClass")
    public void selectAllBookClass(Integer parid,Model model){
        List<Bookorder> bookorders = bookorderService.selectAllBookClass(parid);
        model.addAttribute(bookorders);
    }


    //查询已登录用户的订单
    @RequestMapping("/order")
    public String order( HttpSession session, Model model){
        Parents parent = (Parents) session.getAttribute("loginParent");

        List<Bookorder> orders = bookorderMapper.findAllOrder(parent.getParid());
        model.addAttribute("orders",orders);
        return  "userpage";

    }
}

